package cn.sll.system.controller;

import cn.sll.base.util.AjaxResult;
import cn.sll.base.util.PageList;
import cn.sll.system.domain.SystemDictionAryType;
import cn.sll.system.query.SystemDictionAryTypeQuery;
import cn.sll.system.service.ISystemDictionAryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sdat")
public class SystemDictionAryTypeController {

    @Autowired
    private ISystemDictionAryTypeService systemDictionAryTypeService;

    @GetMapping
    public List<SystemDictionAryType> list(){
        return systemDictionAryTypeService.findAll();
    }

    @GetMapping("/{id}")
    public SystemDictionAryType findById(@PathVariable("id") Long id){
        return systemDictionAryTypeService.findById(id);
    }

    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody SystemDictionAryType systemDictionAryType){

            if (systemDictionAryType.getId()!=null){
                systemDictionAryTypeService.update(systemDictionAryType);
            }else {
                systemDictionAryTypeService.add(systemDictionAryType);
            }
        return  AjaxResult.me().success();
    }

    @DeleteMapping("/{id}")
    public AjaxResult deleteById(@PathVariable("id") Long id) {
        systemDictionAryTypeService.delete(id);
        return  AjaxResult.me().success();
    }

    @PostMapping
    public PageList<SystemDictionAryType> queryByPage(@RequestBody SystemDictionAryTypeQuery query){
        return systemDictionAryTypeService.queryByPage(query);
    }

    @PatchMapping()
    public AjaxResult batchDelete(@RequestBody List<Long> ids){
        systemDictionAryTypeService.batchDelete(ids);
        return AjaxResult.me().success();
    }

}
